﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Waaahsabi.Controls.DWM
{
	// ReSharper disable UnaccessedField.Local
#pragma warning disable 169 //resharper
	[TemplateVisualState(GroupName = "Default", Name = "Idle")]
	[TemplateVisualState(GroupName = "Default", Name = "MouseOver")]
	[TemplateVisualState(GroupName = "Default", Name = "MouseDown")]
	public class TaskBarButton : Control
	{
		private Button _button;
		private Grid _layoutRoot;
		public event EventHandler Click;
		public Guid WindowId;


		public static readonly DependencyProperty ContentProperty =
		DependencyProperty.Register
			(
			"Content",
			typeof(object),
			typeof(TaskBarButton),
			new PropertyMetadata(null)
			);

		public object Content
		{
			get { return GetValue(ContentProperty); }
			set { SetValue(ContentProperty, value); }
		}

		private object _toolTip;
		private string _toolTipText;
		public string ToolTipText
		{
			get
			{
				return _toolTipText;
			}

			set
			{
				_toolTipText = value;
				_toolTip = _toolTipText;
			}
		}
		public TaskBarButton()
		{
			DefaultStyleKey = typeof(TaskBarButton);
		}

		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			_layoutRoot = GetTemplateChild("LayoutRoot") as Grid;
			VisualStateManager.GoToState(this, "Idle", false);
		}

		protected override void OnMouseEnter(MouseEventArgs e)
		{
			VisualStateManager.GoToState(this, "MouseOver", true);
			//base.OnMouseEnter(e);
		}

		protected override void OnMouseLeave(MouseEventArgs e)
		{
			VisualStateManager.GoToState(this, "Idle", true);
			//base.OnMouseLeave(e);
		}

		protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
		{
			if (Click != null)
				Click(this, e);
			VisualStateManager.GoToState(this, "MouseDown", true);
			//base.OnMouseLeftButtonDown(e);
		}

		protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
		{
			VisualStateManager.GoToState(this, "MouseOver", true);
			//base.OnMouseLeftButtonUp(e);
		}
	}
}
